<?php
/**
 * 角色表
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/8
 * Time: 16:35
 */

namespace App\Http\Controllers\Admin;


use App\Http\Traits\RoleTrait;
use App\Http\Logics\Admin\RoleLogic;
use App\Http\Controllers\BaseController;
class RoleController extends BaseController
{
    use RoleTrait;

    /**
     * 获取小程序列表
     * @return string
     */
    public function getMiniProgramList()
    {
        $user_id = $this->user_id;
        $limit = $this->limit;
        $type = $this->type;
        $name = $this->name;
        $data = [
            'user_id' => $user_id,
            'limit' => $limit,
            'type' => $type,
            'name' => $name
        ];
        $response = RoleLogic::getMiniProgramList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
    /**
     * 创建小程序(角色的一种类型)
     */
    public function createMiniProgram()
    {
        $name = $this->name;
        $type = $this->type;
        $app_key = $this->app_key;
        $appid = $this->appid;
        $secret = $this->secret;
        $data = [
            'name' => $name,
            'type' => $type,
            'app_key' => $app_key,
            'appid' => $appid,
            'secret' => $secret
        ];
        $response = RoleLogic::createMiniProgram($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
    /**
     * 删除小程序
     * @return string
     * @throws \Exception
     */
    public function deleteMiniprogram()
    {
        $id =  $this->id;
        $data = [
            'id' => $id
        ];
        $response = RoleLogic::deleteMiniprogram($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
    /**
     * 创建角色
     * @return string
     */
    public function createRole()
    {
        $name = $this->name;
        $type = $this->type;
        $data = [
            'name' => $name,
            'type' => $type
        ];
        $response = RoleLogic::createRole($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 删除角色
     * @return string
     * @throws \Exception
     */
    public function deleteRole()
    {
        $id =  $this->id;
        $data = [
            'id' => $id
        ];
        $response = RoleLogic::deleteRole($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 获取角色列表
     * @return string
     */
    public function getRoleList()
    {
        $user_id = $this->user_id;
        $limit = $this->limit;
        $type = $this->type;
        $data = [
            'user_id' => $user_id,
            'limit' => $limit,
            'type' => $type
        ];
        $response = RoleLogic::getRoleList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 给角色设置菜单
     * @return string
     */
    public function setRoleMenu()
    {
        $role_id = $this->role_id;
        $menu_list = $this->menu_list;
        $data = [
            'role_id' => $role_id,
            'menu_list' => $menu_list
        ];
        $response = RoleLogic::setRoleMenu($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 获取角色的菜单列表
     * @return string
     */
    public function getRoleMenuList()
    {
        $role_id = $this->role_id;
        $data = [
            'role_id' => $role_id
        ];
        $response = RoleLogic::getRoleMenuList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 获取小程序用户的菜单列表
     */
    public function getMiniProgramUserMenuList()
    {
        $role_id = $this->role_id;
        $data = [
            'role_id' => $role_id
        ];
        $response = RoleLogic::getMiniProgramUserMenuList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}